<?php
class BlogController extends AuthController{
  private $db;//模型
  public function __init(){
	$this->db=new BlogModel;
  }


// 显示栏目表
public function index(){
	$data=$this->db->getAll();
	$this->assign('data',$data['blog']);
	$this->assign('page',$data['page']);
	$this->display('index.html');
}


// 添加栏目
public function add(){
    if(IS_POST){
        if($this->db->addBlog()){
     	    $this->success('添加成功',__CONTROLLER__);
        }else{
     	    $this->error($this->db->error);
        }
// 读取栏目
    }else{
         $category=new CategoryModel;
         $categoryDate=$category->getAll();
         $this->assign('categoryDate',$categoryDate);
         $this->display('add.html');

  }
}
// 修改blog
 public function edit(){
    if(IS_POST){

    	if($this->db->editBlog()){
    		$this->success('修改成功',__CONTROLLER__);
      }else{
    		$this->error($this->db->error);
    	}

    }else{
     // 读取博客
       // p($bid);
    	$bid=$_GET['bid'];

    	$filed=$this->db->where('bid='.$bid)->find();
    	// 分配栏目
    	$category=new CategoryModel;
    	$categoryDate=$category->getAll();
    	// 当前博客栏目为选中状态
    	foreach ($categoryDate as $id => $cat) {
    		$categoryDate[$id]['selected']=$cat['cid']==$filed['cid']?" selected''":'';
    	}
    	$this->assign('categoryDate',$categoryDate);
    	$this->assign('filed',$filed);
    	$this->display('edit.html');

      }



  }

}


?>